﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Xml;
using System.IO;
using System.Timers;

namespace Utility
{
    static class TaskLoader
    {
        static IEnumerable<ElapsedEventHandler> LoadTask()
        {
            using (FileStream fs = File.OpenRead("TaskConfig.xml"))
            {
                XmlReader reader = XmlReader.Create(fs);
                string assemblyName = reader.ReadElementString("AssemblyName");
                string nameSpaceValue = reader.ReadElementString("Namespace");
                string classHost = reader.ReadElementString("HostClassName");
                string methodName = reader.ReadElementString("TaskMethodName");

                Assembly assembly = Assembly.Load(assemblyName);
                Type type = assembly.GetType(nameSpaceValue + "." + classHost);
                yield return (ElapsedEventHandler)Delegate.CreateDelegate(typeof(ElapsedEventHandler), type.GetMethod(methodName));
            }

            
        }
    }
}
